package com.resume.bean;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.resume.enums.ResultEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.ToString;

/**
 * 全局统一返回结果类型
 *
 * @author 梁云亮
 */
@ApiModel(value = "全局统一返回结果类型：Result")
@Getter // 必须得提供getter方法，否则Controller返回的数据为空
@ToString
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result<T> {
    /**
     * 返回状态码
     */
    @ApiModelProperty(value = "返回状态码")
    private int code;
    /**
     * 返回的消息
     */
    @ApiModelProperty(value = "返回的消息")
    private String msg;
    /**
     * 返回的数据
     */
    @ApiModelProperty(value = "返回的数据")
    private T data;

    public Result() {
    }

    public Result(ResultEnum resultEnum) {
        this.code = resultEnum.getCode();
        this.msg = resultEnum.getMsg();
    }


    //返回Result本身：方便链式编程
    public Result<T> setCode(int code) {
        this.code = code;
        return this;
    }

    public Result<T> setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public Result<T> setData(T data) {
        this.data = data;
        return this;
    }

}
